package qeug.shsh.opplugin;

import kd.bos.form.field.BasedataEdit;
import kd.bos.form.field.events.BeforeF7SelectEvent;
import kd.bos.form.field.events.BeforeF7SelectListener;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.list.ListShowParameter;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;

import java.util.ArrayList;
import java.util.EventObject;
import java.util.List;

//注册使用单据：付款申请单，差旅报销单，费用报销单，借款单
// 收款信息分录中收款人（供应商）列表过滤：付款申请单：显示Sk01,SK02,SK04,SK97;借款单，差旅报销单，费用报销单：显示SK98
public class SupplierFilterBillPlugin extends AbstractFormPlugin implements BeforeF7SelectListener {

    @Override
    public void registerListener(EventObject e) {
        super.registerListener(e);
        // 供应商F7标识
        BasedataEdit supplier = getView().getControl("supplier");
        if (supplier != null) {
            supplier.addBeforeF7SelectListener(this);
        }
    }

    @Override
    public void beforeF7Select(BeforeF7SelectEvent arg0) {
        ListShowParameter show = (ListShowParameter) arg0.getFormShowParameter();
        List<QFilter> qFilter1 = new ArrayList<>();
        List<QFilter> qFilter2 = new ArrayList<>();
        String name = this.getModel().getDataEntityType().getName();
        if ("er_publicreimbursebill".equals(name)) {
            //付款申请单才进入
            qFilter1.add(new QFilter("number", QCP.in, new String[]{"SK01", "SK02", "SK04", "SK97"}));
            show.getTreeFilterParameter().setQFilters(qFilter1);//左树过滤
            qFilter2.add(new QFilter("group.number", QCP.in, new String[]{"SK01", "SK02", "SK04", "SK97"}));
            show.getListFilterParameter().setQFilters(qFilter2);//右表过滤
        } else {
            // 差旅报销单，费用报销单，借款单才进入
            qFilter1.add(new QFilter("number", QCP.in, new String[]{"SK98"}));
            show.getTreeFilterParameter().setQFilters(qFilter1);//左树过滤
            qFilter2.add(new QFilter("group.number", QCP.in, new String[]{"SK98"}));
            show.getListFilterParameter().setQFilters(qFilter2);//右表过滤
        }
    }
}
